<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>生产成品入库编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script src="${ctx}/js/jsp/date.js" type="text/javascript"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/logic/logicMesWare";
var grid;
var url;
$(function(){
	$("#inputForm").validate({
		onsubmit : true,
		/*执行ajaxsubmit  */
		submitHandler : function(editform) {
			//alert(jsonInfo); 
			try {
				url = basic_Url + "/save.do";
				var api = frameElement.api;
				var W = api.opener;

				//getReturnMessage(url, "inputForm", success_function);
				getReturnMessage(url, "inputForm", W.searchAP);
			} catch (e) {
				alert(e)
			}
		}
	});
	
	var column =  [
					  { display: 'id', name: 'id',width:1, hide:1 },
					  { display: '物料id', name: 'materialsid', width:1,hide:1 },
					  { display: '<font color="gray">产品编码</font>', name: 'code', width: 100 },
	                  { display: '<font color="gray">产品名称</font>', name: 'name', width: 100 },
	                  { display: '<font color="gray">封装类型</font>', name: 'packageType', width: 90 },
	                  { display: '<font color="gray">产品型号</font>', name: 'spec', width: 250 },
	                  { display: '<font color="gray">外箱号</font>', name: 'containerNumber', width: 110},
	                  { display: '<font color="gray">批次</font>', name: 'batch', width: 120},
	                  { display: '<font color="gray">基本单位</font>', name: 'unit', width: 60},
	                  { display: '<font color="gray">基本单位应收数量</font>', name: 'receivable', width: 120},
	                  { display: '<font color="gray">基本单位实收数量</font>', name: 'received', width: 120},
	                  { display: '<font color="gray">等级</font>', name: 'state', width: 80,
	                	  render: function (item){
	                		  var state=item.state;
	                		  if(state=="1"){
	                			  return "一等品";
	                		  }
	                		  if(state=="2"){
	                			  return "次品";
	                		  }
	                		  if(state=="3"){
	                			  return "旧件";
	                		  }
	                	  }}
	                  ];
    var griddata ={};
	grid = $("#table1").ligerGrid({
        columns: column,
                  enabledEdit: true,
                  usePager: true,pageSize:1000,pageSizeOptions:[1000],
                  //data : griddata,
                  parms:[{ name : 'id' , value : '${logicMesWareDO.id}'}],
		          url : basic_Url+"/griditems.do",
                  width: "100%", height:"80%", checkbox: true,
//                   toolbar: { items: [
//                                      { text: '删除',img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
//                                      ]
//                                      }
                  });
	
	$("#pageloading").hide();
	
	$("#meswarecode").change(function(){ 
		if($("#meswarecode").val()==""){
			$.dialog.alert("您选择的订单不能为空");
			return false;
		}
		$.ajax({
	      	url: "${ctx}/yd/logic/logicMesWare/getWh.do",
	      	global: false,
	      	type: "POST",
	     	dataType: "json",
	      	data: ({
	    	  	id : $("#meswarecode").val()
	      	}),		     
	      	success: function(msg){
	      		$("#whname").val(msg.whname);
	      		$("#whcode").val(msg.whcode);
	      		$("#transactionDate").val(msg.transactionDate);
	   		}
		});
		multipleSearch("#table1",true,"",basic_Url+"/mesItemlist.do?ID="+$("#meswarecode").val());
	}); 
	

	
	
	if('${logicMesWareDO.billstatus}' != "" && '${logicMesWareDO.billstatus}' != "1"){
		$("input").attr("readonly","readonly");
		$("input").attr("onclick","");
		$("select").attr("disabled","disabled");
	}
	
	if('${logicMesWareDO.billstatus}' == ""){
		$("#save1").hide();//禁用提交按钮
		$("#save2").hide();//禁用审核按钮
		$("#bohui").hide();//禁用驳回按钮
	}
	else if('${logicMesWareDO.billstatus}' == "1" ){
		$("#save").hide();//禁用保存按钮
		$("#save2").hide();//禁用审核按钮
		$("#bohui").hide();//禁用驳回按钮
        if($("#createname").val()!="${user.name}"){
			$("#save1").hide();//禁用提交按钮
			$("input[type!='hidden']").attr("disabled",true);//禁用SELECT标签
			$("select").attr("disabled",true);//禁用SELECT标签
			$("textarea").attr("disabled",true);//禁用TEXTAREA标签
           }  
	}
	else if('${logicMesWareDO.billstatus}' == "2" ){
		$("#save1").hide();//禁用保存按钮
		$("#save").hide();//禁用保存按钮
		$("input[type!='hidden']").attr("disabled",true);//禁用SELECT标签
		$("select").attr("disabled",true);//禁用SELECT标签
		$("textarea").attr("disabled",true);//禁用TEXTAREA标签
	}
	else{
		$("#save").hide();//禁用保存按钮
		$("#save1").hide();//禁用保存按钮
		$("#save2").hide();//禁用保存按钮
		$("#bohui").hide();
		$("input[type!='hidden']").attr("disabled",true);//禁用SELECT标签
		$("select").attr("disabled",true);//禁用SELECT标签
		$("textarea").attr("disabled",true);//禁用TEXTAREA标签
	}
	
	<c:forEach items='${itemDOs}' var='item'>
    	grid.addRow2({
    		id: "${item.id}",
    		materialsid: "${item.materialsid}",
    		containerNumber: "${item.containerNumber}",
    		code: "${item.code}",
    		name: "${item.name}",
    		spec: "${item.spec}",
    		unit : "${item.unit}",
    		packageType : "${item.packageType}",
    		state : "${item.state}",
    		batch : "${item.batch}",
    		receivable : "${item.receivable}",
    		received : "${item.received}"
        });
    </c:forEach>
    
})


function submitForm(param){
	var data = grid.getData();
	jQuery.ajaxSettings.async = false;
		$("#type").val(param);
		$("#itemdata").val(JSON.stringify(data));
		$("#submitFlag").val(param);
		$("#inputForm").submit();
}
	
	
// 	function exportAP(){
// 		var id=$("#id").val();//JSON.stringify(grid.getData());
// 		if(id!=""){
// 			var path = basic_Url+"/exportExcel.do?id="+id;
// 	   		window.open(path,"_blank");
// 		}
// 		else{
// 			$.dialog.alert("请先保存再导出");
// 		}
// 	}
	
	function bhcheck(){
		if($("#id").val()==""){
			$.dialog.alert("没有提交无法驳回");
			return false;
		}
		$.ajax({
	      	url: "${ctx}/yd/logic/logicMesWare/updateState.do",
	      	global: false,
	      	type: "POST",
	     	dataType: "json",
	      	data: ({
	    	  	rows : $("#id").val()
	      	}),		     
	      	success: function(msg){
	    	  	if(msg.msg=="SUCCESS"){
	    		  	$.dialog.alert("驳回成功");
	    	  	}
	    	  	if(msg.msg=="ERROR"){
	    		  	$.dialog.alert("驳回失败");
	    	  	}
	    	  	CloseDialog();
	    	  	var api = frameElement.api;
	         	var W = api.opener;
	            W.searchAP();
	   		}
		});
	}
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${logicMesWareDO.id}"/>
<input type="hidden" id="version" name="version" value="${logicMesWareDO.version}"/>
<input type="hidden" id="itemdata" name="itemdata" value=""/>
<input type="hidden" id="itemdelete" name="itemdelete" value=""/>
<input type="hidden" id="type" name="type" value=""/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
         		<tr>
         					<c:if test="${not empty logicMesWareDO.erpwarecode}">
	                    		   <td nowrap>ERP入库单号:</td>
	                    			<td >
		   		                 	<input type="text"  id="erpwarecode" name="erpwarecode" value="${logicMesWareDO.erpwarecode}" class="inp_width_98p" readonly="readonly"/>
		   		            		</td>
		   		            		<td nowrap="nowrap" width="20%">建单时间:</td>
						<td width="30%"><input class="inp_width_98p" type="text" id="dctime" name="dctime"
							value="<fmt:formatDate value="${empty logicMesWareDO.dctime?nowDate:logicMesWareDO.dctime}" type="both" dateStyle="long" pattern="yyyy-MM-dd" />" readonly="readonly"/></td>
	   		            	</c:if>
   		           </tr>
   		           <tr>
                    	<td nowrap>MES入库单号:</td>
                    	<c:choose>
                    		<c:when test="${empty logicMesWareDO.meswarecode}">
                    			<td>
		   		                  <select id="meswarecode" name="meswarecode" class="inp_width_98p required">
		   		                 	<option></option>
		   		                 	<c:forEach items='${xList}' var='xList' varStatus="i">
		   		                 		<option value='${ xList}'>${ xList}</option>
		   		                 	</c:forEach>
		   		                 	</select>
	   		                 </td>
                    		</c:when>
                    		<c:otherwise>
                    			<td>
	   		                 	<input type="text"  id="meswarecode" name="meswarecode" class="inp_width_98p" value="${logicMesWareDO.meswarecode}"  readonly="readonly"/>
	   		            		</td>
                    		</c:otherwise>
                    	</c:choose>
	                    	
	   		                 
                    	<td nowrap>制单人:</td>
	                    	<td>
	   		                 	<input type="text"  id="createname" name="createname" value="${logicMesWareDO.createname == null ? user.name : logicMesWareDO.createname}" class="inp_width_98p" readonly="readonly"/>
	   		            </td>
   		           </tr>
   		            <tr>
                    	<td nowrap>仓库名称:</td>
	                    	<td>
		                    		<input type="hidden"  id="whcode" name="whcode" value="${logicMesWareDO.whcode }"/>
		   		                 	<input type="text" class="inp_width_98p required" id="whname" name="whname" value="${logicMesWareDO.whname }" readonly="readonly"/>
	   		            </td>
	   		            
	   		            <td nowrap>交易时间:</td>
	                    	<td>
	                    		<input id="transactionDate" name="transactionDate" class="inp_width_98p required" readonly="readonly" value="<fmt:formatDate value="${logicMesWareDO.transactionDate}" pattern="yyyy-MM-dd" type="both" />" />
	   		            	</td>
   		           </tr>
   		           <tr>
                    	<td nowrap>备注:</td>
	                    	<td colspan="3">
	   		                 	<input type="text"  id="remark" name="remark" class="inp_width_98p" value="${logicMesWareDO.remark }" size="40" />
	   		            </td>
   		           </tr>
                </table>
                <div id="table1"> </div> 
                <div id="table2"> </div>               
         </div>
         
	<div class="formBar">
	        <ul>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm(1)">保存</button></div></div></li>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save1" onclick="submitForm(2)">提交</button></div></div></li>
		       <webres:displaycontroller elementId="MESRK_BH_CHEECK_PH" description="MES生产入库驳回">
		       		<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="bohui" onclick="bhcheck()">驳回</button></div></div></li>
		      	</webres:displaycontroller>
		       <webres:displaycontroller elementId="MESRK_SP_CHEECK" description="MES生产审核">
		       			<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save2" onclick="submitForm(3)">审核</button></div></div></li>
		      		</webres:displaycontroller>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>
    </div>
</form>
</body>
</html>
